package com.zhouyibike.uu.ui.activity.redwallet;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.Gravity;
import android.view.View;
import android.widget.ImageButton;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.robinhood.ticker.TickerUtils;
import com.robinhood.ticker.TickerView;
import com.zhouyibike.uu.R;
import com.zhouyibike.uu.ui.activity.yihoudong.YihuodongActivity3;
import com.zhouyibike.uu.ui.base.BaseActivity;
import com.zhouyibike.uu.utils.Util;

public class OpenrwActivity extends BaseActivity implements View.OnClickListener {
    private ImageButton mBtnBack;
    private TextView mBtnTitle;
    private TickerView tickerView;
    private TextView wanfashuomingtv, openrw_myyiquan, maxhongbaotv;
    int i = 10;
    int time = 0;
    private RelativeLayout tututu;
    Handler handler = new Handler(new Handler.Callback() {
        @Override
        public boolean handleMessage(Message message) {
            time++;
//            Random random = new Random();
            i = i + 55;
            String str = (i + "").substring((i + "").length() - 2);
            tickerView.setText(str, true);
            handler.sendEmptyMessageDelayed(0, 100);
            if (time == 30) {
                tickerView.setAnimationDuration(100);
                if (curhongbao < 10) {
                    tickerView.setText("0" + curhongbao + "", true);
                } else {
                    tickerView.setText(curhongbao + "", true);
                }
                handler.removeMessages(0);
            }
            return false;
        }
    });
    private int curhongbao, maxhongbao;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_openrw);
        try {
            curhongbao = Integer.parseInt(getIntent().getStringExtra("hongbaovalue"));
            maxhongbao = Integer.parseInt(getIntent().getStringExtra("maxhongbao"));
        } catch (Exception e) {
            e.printStackTrace();
        }
        initView();
        initlistener();
        maxhongbaotv.setText("最高"+maxhongbao + "翼券");
        handler.sendEmptyMessage(0);
    }

    private void initlistener() {
        wanfashuomingtv.setOnClickListener(this);
        openrw_myyiquan.setOnClickListener(this);
        tututu.setOnClickListener(this);
    }

    private void initView() {
        tututu= (RelativeLayout) findViewById(R.id.tututu);
        maxhongbaotv = (TextView) findViewById(R.id.maxhongbao);
        openrw_myyiquan = (TextView) findViewById(R.id.openrw_myyiquan);
        wanfashuomingtv = (TextView) findViewById(R.id.wanfashuomingtv);
        tickerView = (TickerView) findViewById(R.id.openrw_center);
        tickerView.setTextColor(Color.WHITE);
        tickerView.setTextSize(Util.dp2px(this, 40));
        tickerView.setAnimationDuration(200);
        tickerView.setAnimateMeasurementChange(true);
        //tickerView.setAnimationInterpolator(new OvershootInterpolator());
        tickerView.setGravity(Gravity.START);
        tickerView.setCharacterList(TickerUtils.getDefaultNumberList());
        mBtnBack = (ImageButton) findViewById(R.id.bar_btn_back);
        mBtnTitle = (TextView) findViewById(R.id.bar_text_title);
        mBtnTitle.setText("领红包");
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.bar_btn_back:
                finish();
                break;
            case R.id.wanfashuomingtv:
                Intent intowanfashuoming = new Intent(this, ScanrwActivity.class);
                intowanfashuoming.putExtra("isgone", true);
                startActivity(intowanfashuoming);
                break;
            case R.id.openrw_myyiquan:
                Intent intomyyiquan = new Intent(this, YihuodongActivity3.class);
                startActivity(intomyyiquan);
                break;
            case R.id.tututu:
                Intent intomyyiquan2 = new Intent(this, YihuodongActivity3.class);
                startActivity(intomyyiquan2);
                break;
        }

    }
}
